package com.haust.dianqi.web;

import com.haust.dianqi.pojo.User;
import com.haust.dianqi.pojo.UserFile;
import com.haust.dianqi.service.UserFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Auther: csp1999
 * @Date: 2020/04/27/9:45
 * @Description:
 */
@Controller
public class IndexController {
    @Autowired
    private UserFileService userFileService;

    @GetMapping("/login")
    public String toLogin() {
        return "/admin/login";
    }

    @GetMapping("/index")
    public String toIndex() {
        return "index";
    }

    @GetMapping("/toXueYuanGaiKuang")
    public String toXueYuanGaiKuang() {
        return "xueYuanGaiKuang";
    }

    @GetMapping("/toShiziduiwu")
    public String toShiziduiwu() {
        return "shiziduiwu";
    }

    @GetMapping("/toKexueyanjiu")
    public String toKexueyanjiu() {
        return "kexueyanjiu";
    }

    @GetMapping("/toTuanduigongzuo")
    public String toTuanxuegongzuo() {
        return "tuanduigongzuo";
    }

    @GetMapping("/toZhaoshengjiuye")
    public String toZhaoshengjiuye() {
        return "zhaoshengjiuye";
    }

    @GetMapping("/toHezuojiaoliu")
    public String toHezuojiaoliu() {
        return "hezuojiaoliu";
    }

    @GetMapping("/toRencaipeiyang_benke")
    public String toRencaipeiyang_benke() {
        return "rencaipeiyang_benke";
    }

    @GetMapping("/toRencaipeiyang_yanjiusheng")
    public String toRencaipeiyang_yanjiusheng() {
        return "rencaipeiyang_yanjiusheng";
    }


    @GetMapping("/addArticle")
    public String addArticle(HttpSession session, Model model){
        //在登录的session中获取用户的id
        User user = (User) session.getAttribute("user");
        //根据用户id查询所有的文件信息
        List<UserFile> userFiles = userFileService.findByUserId(user.getId());
        System.out.println(userFiles);
        //存入作用域中
        model.addAttribute("files", userFiles);
        return "/admin/addArticle";
    }

//    @GetMapping("/news/{type}")
//    public String news(@PathVariable("type") String type, Model model){
//
//
//
//        return "news";
//    }
}
